package com.shiguiwu.springmybatis.spring.conditional;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @description: 没有才注册的bean
 * @author: stone
 * @date: Created by 2021/3/15 13:45
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.conditional
 */
public class OnMissingBeanCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        System.out.println("条件判断。。。。。。。。。。。。。。。");
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
//        String[] beanNamesForType = beanFactory.getBeanNamesForType(ICondition.class);
        assert beanFactory != null;
        Map<String, ICondition> beansOfType = beanFactory.getBeansOfType(ICondition.class);
        return beansOfType.isEmpty();
    }
}
